package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.component.SettingForm;
import com.github.aloxc.plugin.restplus.component.YapiSettingForm;
import com.github.aloxc.plugin.restplus.entity.SettingFormType;
import com.github.aloxc.plugin.restplus.entity.SettingListenerContext;
import com.github.aloxc.plugin.restplus.i18n.I18Bundle;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * ypi设置
 */
public class YapiSettingMouseListener implements ActionListener  {
    private SettingForm settingForm;

    public YapiSettingMouseListener(SettingForm settingForm) {
        this.settingForm = settingForm;
    }
    @Override
    public void actionPerformed(ActionEvent e) {

        GridLayoutManager layoutManager = new GridLayoutManager(1, 1);
        layoutManager.setHGap(1);
        layoutManager.setVGap(1);
        layoutManager.setMargin(new Insets(0,0,0,0));
        settingForm.getDialog().setTitle(I18Bundle.getMessage("com.github.aloxc.plugin.restplus.setting.yapi.title"));
        YapiSettingForm yapiSettingForm = new YapiSettingForm(settingForm.getProject(),new SettingListenerContext(SettingFormType.YAPI,null));
        yapiSettingForm.setDialog(settingForm.getDialog());
        Dimension size = new Dimension(-1, -1);
        if(settingForm.getRightPane().getComponentCount() > 0) {
            settingForm.getRightPane().remove(0);
        }
        settingForm.getRightPane().add(yapiSettingForm,
                new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_BOTH,
                        GridConstraints.FILL_NONE,
                        GridConstraints.FILL_NONE,
                        size, size, size));
        settingForm.updateUI();;


    }
}
